package framework.portals;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import org.testng.internal.PropertiesFile;

import webdriver.PropertiesResourceManager;

public class PortalManager {
	
	public final String PORTALS_PROPS_FILE = "stage.properties";
	private Properties properties;
	
	public Properties readPortals(){
		init();
		properties = initPropsFromResource(properties, PORTALS_PROPS_FILE);
		return properties;
	}
	
	private void init(){
		properties = new Properties();
	}
	
	/**
	 * Объединение двух properties-файлов (параметры из 2-го файла переопределяют параметры из 1-го)
	 * @param objProperties Properties
	 * @param resourceName Resource Name
	 * @return Properties
	 */
	private Properties initPropsFromResource(final Properties objProperties, final String resourceName) {
		InputStream inStream = this.getClass().getClassLoader().getResourceAsStream(resourceName);

		if (inStream != null) {
			try {
				objProperties.load(inStream);
				inStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			System.err.println(String.format("Resource \"%1$s\" could not be found", resourceName));
		}
		return objProperties;
	}

}
